package cc.douquan.com.doutu.view.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;

import cc.douquan.com.doutu.R;
import cc.douquan.com.doutu.utils.CollectionDialog;
import cc.douquan.com.doutu.utils.ToastUtils;
import cc.douquan.com.doutu.weight.MyProgressWebView;

/**
 * Created by guangjiego on 2016/11/24.
 */

public class WebActivity extends Activity {
    private String url;
    private MyProgressWebView webview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.web_activity);
        url = this.getIntent().getStringExtra("url");
        webview = (MyProgressWebView) findViewById(R.id.mainWebView);
        webview.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                WebView.HitTestResult result = ((WebView) v).getHitTestResult();
                int type = result.getType();
                if (type == WebView.HitTestResult.IMAGE_TYPE) {
                    String imgurl = result.getExtra();
                    CollectionDialog.showDialog(WebActivity.this, imgurl);
                    ToastUtils.showShort(imgurl);
                }
                return true;
            }
        });
        WebSettings webSettings = webview.getSettings();
        //设置WebView属性，能够执行Javascript脚本
        webSettings.setJavaScriptEnabled(true);
        //设置可以访问文件
        webSettings.setAllowFileAccess(true);
        webview.loadUrl(url);
    }
}
